package com.lg.erp.service.impl.zhangchaofu;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.erp.entity.zhangchaofu.*;
import com.lg.erp.mapper.zhangchaofu.InAndOutWarehouseMapper;
import com.lg.erp.service.zhangchaofu.InAndOutWarehouseSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class InAndOutWarehouseSeviceImpl extends ServiceImpl<InAndOutWarehouseMapper, TIomWarehouse> implements InAndOutWarehouseSevice {

    @Autowired
    private InAndOutWarehouseMapper inAndOutWarehouseMapper;


    @Override
    public List<ZCFTProductHandover> findInWarehouseProductHandover() {
        ZCFTProductHandover productHandover = new ZCFTProductHandover();
        return inAndOutWarehouseMapper.findInWarehouseProductHandover(productHandover);
    }

    @Override
    public List<ZCFTProductHandover> findInWarehouseProductHandoverType(String type) {
        ZCFTProductHandover productHandover = new ZCFTProductHandover();
        productHandover.setType(Long.parseLong(type));
        return inAndOutWarehouseMapper.findInWarehouseProductHandover(productHandover);
    }

    @Override
    public void addIomWarehouse(TIomWarehouse tIomWarehouse) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");//可以方便地修改日期格式
        String time = dateFormat.format(now);
        java.sql.Date tim = java.sql.Date.valueOf(time.replace("/", "-"));
        String id = UUID.randomUUID().toString().replace("-", "").substring(0, 20);
        //获得该货位id上的数据
        ZCFTCargo cargo =inAndOutWarehouseMapper.getCargoMessage(tIomWarehouse.getIomCargoloca());
        //查询对应的货区
        ZCFTCargoArea cargoArea = inAndOutWarehouseMapper.getCargoAreaMessage(cargo);
        tIomWarehouse.setCargoId(tIomWarehouse.getIomCargoloca());
        tIomWarehouse.setIomCargoloca(cargo.getCargoNo());
        tIomWarehouse.setIomArea(cargoArea.getGoodsName());
        tIomWarehouse.setIomShelves(cargo.getShelvesId());
        tIomWarehouse.setId(id);

        tIomWarehouse.setIomTime(tim);
        //在货位表上添加商品数据
        inAndOutWarehouseMapper.addIomWarehouse(tIomWarehouse);
        //出入库详情表上添加数据
        inAndOutWarehouseMapper.addIomWarehouseMessage(tIomWarehouse);
    }

    @Override
    public void addInWarehouse(ZCFTIoWarehouse ioWarehouse) {
        String id = UUID.randomUUID().toString().replace("-", "").substring(0, 20);
        ioWarehouse.setId(id);
        ioWarehouse.setCompanyId("1");
        inAndOutWarehouseMapper.addInWarehouse(ioWarehouse);
    }
}
